#By WangZhiyu(imwangzhiyu@outlook.com)
#We will dream it possible!!!
import os
import socket
import subprocess
from tkinter import *
from tkinter import filedialog

print("Welcome to easyftp! My E-Mail accress is imwangzhiyu@outlook.com")
#交互界面
window = Tk()#定义窗口
window.title("Easy-FTP")#窗口标题
window.geometry("350x200")#窗口大小
#选择端口
porttip = Label(window, text="选择端口")#选择端口提示
porttip.grid(column=0, row=0)#选择端口提示
inport = Entry(window, width=10)#输入端口变量框
inport.grid(column=1, row=0)#输入端口变量框
port = inport.get()#端口变量
#选择文件夹
path = "C:"
def pickpath():
    path = filedialog.askdirectory()#选择文件夹
pathtip = Label(window, text="选择共享文件夹")#选择文件夹提示
pathtip.grid(column=0, row=1)#选择文件夹提示
inpath = Button(window, text="选择文件夹", command=pickpath)#输入文件夹按钮
inpath.grid(column=1, row=1)#输入文件夹按钮
#开启服务
def startftp():
    global ftpser
    ftpser = subprocess.Popen("cd " + path + "&& python -m http.server " + port,shell=True)
start = Button(window, text="开启服务", command=startftp)#开启服务按钮
start.grid(column=0, row=2)#开启服务按钮位置
#关闭服务
def killftp():
    ftpser.kill()
    print("EXIT!")
kill = Button(window, text="关闭服务", command=killftp)#关闭服务按钮
kill.grid(column=1, row=2)#关闭服务按钮位置
window.mainloop()#主窗口循环
